package com.ewanghuiju.app.ui.watermail.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.base.BaseActivity;
import com.ewanghuiju.app.base.contract.watermail.WaterOrderDetailsContract;
import com.ewanghuiju.app.component.ImageLoader;
import com.ewanghuiju.app.model.bean.response.WaterOrderListResponBean;
import com.ewanghuiju.app.presenter.watermail.WaterOrderDetailsPresenter;
import com.ewanghuiju.app.ui.web.MyWebviewActivity;
import com.ewanghuiju.app.util.ClipboardUtils;
import com.ewanghuiju.app.util.LoadingDialogUtils;
import com.ewanghuiju.app.util.StartActivityUtil;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.gyf.immersionbar.ImmersionBar;
import com.makeramen.roundedimageview.RoundedImageView;
import com.muddzdev.styleabletoast.StyleableToast;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 水滴/积分订单详情
 * @time 2020/2/19
 */
public class WaterOrderDetailsActivity extends BaseActivity<WaterOrderDetailsPresenter> implements WaterOrderDetailsContract.View {
    @BindView(R.id.tv_order_name)
    TextView tvOrderName;
    @BindView(R.id.tv_order_number)
    TextView tvOrderNumber;
    //商品图片
    @BindView(R.id.rv_shop)
    RoundedImageView rvShop;
    //订单商品标题
    @BindView(R.id.tv_order_title)
    TextView tvOrderTitle;
    @BindView(R.id.tv_kefu)
    TextView tvKefu;
    //地址信息
    @BindView(R.id.tv_address_details)
    TextView tvAddressDetails;
    //价格
    @BindView(R.id.tv_spe_price)
    TextView tvSpePrice;
    //商品价格
//    @BindView(R.id.tv_shop_price)
//    TextView tvShopPrice;
    //运费
//    @BindView(R.id.tv_yunfei)
//    TextView tvYunfei;
    //实付价格
    @BindView(R.id.tv_order_no)
    TextView tvOrderNo;
    @BindView(R.id.iv_position)
    ImageView ivPosition;
    @BindView(R.id.tv_order_no_copy)
    TextView tvOrderNoCopy;
    @BindView(R.id.tv_create_time)
    TextView tvCreateTime;
    @BindView(R.id.tv_pay_time)
    TextView tvPayTime;
    @BindView(R.id.tv_pay_type)
    TextView tvPayType;
    @BindView(R.id.tv_kd_name)
    TextView tvKdName;
    @BindView(R.id.tv_kd_no)
    TextView tvKdNo;
    @BindView(R.id.tv_kdno_copy)
    TextView tvKdnoCopy;
    @BindView(R.id.tv_kd_fhtime)
    TextView tvKdFhtime;
    @BindView(R.id.layout_fh_time)
    LinearLayout layoutFhTime;
    @BindView(R.id.layout_kd)
    LinearLayout layoutKd;

    //查看物流
    @BindView(R.id.tv_look_wuliu)
    TextView tvLookWuliu;

    @BindView(R.id.tv_order_remarks)
    TextView tvOrderRemarks;
    @BindView(R.id.layout_order_remarks)
    RelativeLayout layoutOrderRemarks;
    @BindView(R.id.layout_order_remarks_line)
    LinearLayout layoutOrderRemarksLine;

    private String orderId;

    private WaterOrderListResponBean waterOrderListResponBean;

    @Override
    protected int getLayout() {
        return R.layout.activity_water_order_details;
    }

    @Override
    protected void initEventAndData() {
        orderId = getIntent().getStringExtra(Constants.WATER_SHOP_ID);
        if (TextUtils.isEmpty(orderId)) {
            StyleableToast.makeText(mContext, "未获取到订单信息", Toast.LENGTH_SHORT, R.style.mytoast).show();
            return;
        }
        LoadingDialogUtils.show(mContext);
        mPresenter.getData(orderId);
    }

    @OnClick({R.id.tv_kdno_copy, R.id.tv_order_no_copy, R.id.tv_kefu, R.id.tv_look_wuliu,})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {
            return;
        }
        switch (view.getId()) {
            case R.id.tv_kdno_copy:
                //快递单号
                if (waterOrderListResponBean != null) {
                    if (TextUtils.isEmpty(waterOrderListResponBean.getOrder_express())) {
                        StyleableToast.makeText(mContext, "快递号为空", Toast.LENGTH_SHORT, R.style.mytoast).show();
                        return;
                    }
                    ClipboardUtils.copyText(waterOrderListResponBean.getOrder_express(), "复制成功");
                }

                break;

            case R.id.tv_order_no_copy:
                if (waterOrderListResponBean != null) {
                    if (TextUtils.isEmpty(waterOrderListResponBean.getOrder_no())) {
                        StyleableToast.makeText(mContext, "订单号为空", Toast.LENGTH_SHORT, R.style.mytoast).show();
                        return;
                    }
                    ClipboardUtils.copyText(waterOrderListResponBean.getOrder_no(), "复制成功");
                }
                break;
            case R.id.tv_kefu:
                //客服
                new StartActivityUtil(mContext, MyWebviewActivity.class).putExtra("url", Constants.WEBURL_KEFU)
                        .putExtra(Constants.WEBURL_TITLE, Constants.WEBURL_KEFU_TITLE).startActivity(true);
                break;
            case R.id.tv_look_wuliu:
                //查看物流
                if (waterOrderListResponBean != null) {
                    if (TextUtils.isEmpty(waterOrderListResponBean.getCourier_link())) {
                        StyleableToast.makeText(mContext, "未查询到信息", Toast.LENGTH_SHORT, R.style.mytoast).show();
                        return;
                    }
                    new StartActivityUtil(mContext, MyWebviewActivity.class).putExtra("url", waterOrderListResponBean.getCourier_link())
                            .putExtra(Constants.WEBURL_TITLE, Constants.WEBURL_KUAIDI_TITLE).startActivity(true);
                }
                break;
            default:
                break;
        }
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(mToolbar)
                .statusBarDarkFont(true)
                .init();
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    public void showContent(WaterOrderListResponBean bean) {
        LoadingDialogUtils.dismissDialog_ios();
        if (bean != null) {
            this.waterOrderListResponBean = bean;

            tvOrderName.setText(TextUtils.isEmpty(bean.getName()) ? "" : bean.getName());

            tvOrderNumber.setText(TextUtils.isEmpty(bean.getMobile()) ? "" : bean.getMobile());

            tvAddressDetails.setText(TextUtils.isEmpty(bean.getAddress()) ? "" : "地址：" + bean.getProvince() +
                    bean.getCity() + bean.getCountry() + bean.getAddress());

            ImageLoader.load(mContext, bean.getGoods_img(), rvShop);

            tvOrderTitle.setText(bean.getGoods_title());

            tvSpePrice.setText(TextUtils.isEmpty(bean.getPay_price()) ? "" : bean.getPay_price());
            //订单号
            tvOrderNo.setText(TextUtils.isEmpty(bean.getOrder_no()) ? "" : bean.getOrder_no());
            //创建时间
            tvCreateTime.setText(TextUtils.isEmpty(bean.getCreate_time()) ? "" : bean.getCreate_time());
            //支付时间
            tvPayTime.setText(TextUtils.isEmpty(bean.getCreate_time()) ? "" : bean.getCreate_time());
            //支付方式
            tvPayType.setText("水滴支付");

            if (TextUtils.isEmpty(bean.getOrder_remark())) {
                layoutOrderRemarks.setVisibility(View.GONE);
                layoutOrderRemarksLine.setVisibility(View.GONE);
            } else {
                layoutOrderRemarks.setVisibility(View.VISIBLE);
                layoutOrderRemarksLine.setVisibility(View.VISIBLE);
                tvOrderRemarks.setText(bean.getOrder_remark());
            }

            if (!TextUtils.isEmpty(bean.getOrder_express())) {
                //快递单号
                layoutKd.setVisibility(View.VISIBLE);
                tvKdName.setText(TextUtils.isEmpty(bean.getDelivery()) ? "暂无" : bean.getDelivery());
                tvKdNo.setText(TextUtils.isEmpty(bean.getOrder_express()) ? "暂无" : bean.getOrder_express());
//                tvKdFhtime.setText(TextUtils.isEmpty(bean.getDelivery_time()) ? "暂无" : bean.getDelivery_time());
            }

            if (bean.getStatus() == 3) {
                tvLookWuliu.setVisibility(View.VISIBLE);
            } else {
                tvLookWuliu.setVisibility(View.GONE);
            }
        }
    }

    @Override
    public void showMoreContent(String list) {

    }

    @Override
    protected int getTitleIntText() {
        return R.string.water_details_title;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
